package com.chushouya.controller.manager.admin;


import com.chushouya.common.constant.ServiceType;
import com.chushouya.manager.dto.admin.article.*;
import com.chushouya.manager.service.admin.ArticleService;
import com.general.framework.core.schema.PageResult;
import com.general.framework.core.schema.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@Api(tags = ServiceType.PLATFORM + "文章管理")
@RestController
@RequestMapping(ServiceType.PLATFORM + "/article")
public class ArticleController {
    @Resource
    private ArticleService articleService;

    @GetMapping("/page")
    @ApiOperation("文章分页列表")
    public Response<PageResult<ArticleListDTO>> page(ArticleQuery query) {
        return Response.success(articleService.selectPage(query));
    }

    @GetMapping("/detail")
    @ApiOperation("文章详情")
    public Response<ArticleDetailDTO> detail(Long articleId) {
        return Response.success(articleService.detail(articleId));
    }

    @PostMapping("/add")
    @ApiOperation("新增文章")
    public Response<Void> save(@RequestBody @Valid ArticleSaveDTO dto) {
        articleService.save(dto);
        return Response.success();
    }

    @PostMapping("/edit")
    @ApiOperation("编辑文章")
    public Response<Void> update(@RequestBody @Valid ArticleUpdateDTO dto) {
        articleService.update(dto);
        return Response.success();
    }

    @PostMapping("/remove")
    @ApiOperation("删除文章")
    public Response<Void> remove(Long id) {
        articleService.remove(id);
        return Response.success();
    }

    @PostMapping("/switchStatus")
    @ApiOperation("切换文章状态")
    public Response<Void> switchStatus(Long id, Integer status) {
        articleService.switchStatus(id, status);
        return Response.success();
    }

}
